package com.shenhaofeng.rxcache.sample;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import com.shenhaofeng.rxcache.CacheDirManager;
import com.shenhaofeng.rxcache.CacheProvider;
import com.shenhaofeng.rxcache.source.MemorySource;
import com.shenhaofeng.rxcache.source.SerializableSource;

import java.io.File;

import rx.functions.Action1;

/**
 * Created by haofeng on 2016/9/25.
 */

public class CacheActivity extends AppCompatActivity {


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        loadCache();
    }


    public void loadCache() {
        CacheDirManager cacheDirManager = new CacheDirManager(this);
        File dir = cacheDirManager.getSubDir("test");
        CacheProvider<String> stringCacheProvider = CacheProvider.create(new MemorySource<String>(20), new SerializableSource<String>(dir));
        stringCacheProvider.put("test", "test");
        stringCacheProvider.cache("test").subscribe(new Action1<String>() {
            @Override
            public void call(String s) {
                System.out.println("message:" + s);
            }
        });
    }
}
